﻿using BaiTu.EventEntity;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace BaiTu.EventServices.Configuration
{
    public static class EventServiceConfiguration
    {
        //public static RedisSettings RedisSettings;
        public static ConfigInfo.RedisConfigInfo RedisSettings;
        //public static SuperSocketSettings SuperSocketSettings;
        public static SuperSocketSettings SuperSocketSettings;
        public static LocalSettings LocalSettings;
        /// <summary>
        /// 事件与对应的处理函数之间的映射
        /// </summary>
        public static List<EventInfo> EventMappings;

        public static EventBusType EventBusType
        {
            get
            {
                EventBusType busType = EventBusType.Redis;
                if (ConfigInfo.EventType.Equals("redis", StringComparison.CurrentCultureIgnoreCase))
                {
                    busType = EventBusType.Redis;
                    RedisSettings=Config.RedisConfig.GetConfig();
                }
                else if (ConfigInfo.EventType.Equals("local", StringComparison.CurrentCultureIgnoreCase))
                {
                    busType = EventBusType.Local;
                }
                else if (ConfigInfo.EventType.Equals("SuperSocket", StringComparison.CurrentCultureIgnoreCase))
                {
                    busType = EventBusType.SuperSocket;
                }
                else
                {
                    throw new Framework.Exceptions.BaiTuCoreException("EventType 必须为有效字符串 redis 、local、SuperSocket");
                }
                return busType;
            }
        }

        private static ConfigInfo.EventBusConfigInfo _configInfo = null;
        public static ConfigInfo.EventBusConfigInfo ConfigInfo
        {
            get
            {
                if (_configInfo == null)
                {
                    _configInfo = Config.EventBusConfig.GetConfig();
                }
                return _configInfo;
            }
        }

        static EventServiceConfiguration()
        {
            EventMappings = new List<EventInfo>();
            _configInfo = Config.EventBusConfig.GetConfig();
         //   Event=evt, EventFullType=evtFullType, EventProcessorType=evtProcessor
        }
    }
}
